package com.sgame.smobigame;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class GameAdapter extends BaseAdapter {

	private Activity activity;
	private ArrayList<HashMap<String, String>> data;
	private static LayoutInflater inflater = null;
	public ImageLoader imageLoader;

	public GameAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
		activity = a;
		data = d;
		inflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		imageLoader = new ImageLoader(activity.getApplicationContext());
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View gameView = convertView;

		if (convertView == null) {
			gameView = inflater.inflate(R.layout.sgame_game_item, null);
		}

		ImageView imgGame = (ImageView) gameView.findViewById(R.id.imgGame);
		ImageView imgOptions = (ImageView) gameView
				.findViewById(R.id.imgOptions);
		TextView tvNameGame = (TextView) gameView.findViewById(R.id.tvNameGame);
		TextView tvDescGame = (TextView) gameView
				.findViewById(R.id.tvDescription);

		HashMap<String, String> games = new HashMap<String, String>();
		games = data.get(position);

		imageLoader.DisplayImage(games.get(GamesView.TAG_ImageMyGame), imgGame);
		imageLoader
				.DisplayImage(games.get(GamesView.TAG_MyOptions), imgOptions);
		tvNameGame.setText(games.get(GamesView.TAG_NameMyGame));
		tvDescGame.setText(games.get(GamesView.TAG_DescMyGame));

		return gameView;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

}
